package galaxy.generator;

public class AbstractNodeVisitor implements NodeVisitor {
	private int depth = 0;
	
	public void visit(Node n)
	{
		depth++;
		enterNode(n);
		for (Node child : n.getChildren()) {
			child.accept(this);
		}
		exitNode(n);
		depth--;
	}
	
	public int getDepth()
	{
		return depth;
	}
	
	public void enterNode(Node n)
	{}
	
	public void exitNode(Node n)
	{}
	
	public static AbstractNodeVisitor printer()
	{
		return new AbstractNodeVisitor() {
			public String getIndent()
			{
				String indent = "";
				for (int i = 0; i < getDepth(); i++) {
					indent = indent.concat("  ");
				}
				return indent;
			}
			
			public void enterNode(Node n)
			{
				System.out.println(getIndent() + n.getValue());
			}
		};
	}
}
